import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
const apiConfig = require('./src/api/config.js')
// import { viteMockServe } from 'vite-plugin-mock'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'


export default defineConfig({
  // plugins: [vue(), viteMockServe()],
  // plugins: [vue()],
  plugins: [
    vue(),
    // viteMockServe({
    //     mockPath: 'mock',
    //     enable: true,
    // }),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  // envPrefix:"APP_", // env文件APP_  为自定义开头名
  resolve:{
    alias:{
      '@':path.resolve('./src')
    }
  },
  // https://cn.vitejs.dev/config/server-options.html#server-proxy

  server: {
    // port: 4000, // 设置服务启动端口号
    // open: true, // 设置服务启动时是否自动打开浏览器
    // cors: true, // 允许跨域

    proxy: apiConfig.proxy,

    // proxy: {
      // '/api': {
      //   target: 'http://jsonplaceholder.typicode.com',
      //   changeOrigin: true,
      //   rewrite: (path) => path.replace(/^\/api/, ''),
      // },

      // 正则表达式写法：http://localhost:5173/fallback/ -> http://jsonplaceholder.typicode.com/
      // '^/fallback/.*': {
      //   target: 'http://jsonplaceholder.typicode.com',
      //   changeOrigin: true,
      //   rewrite: (path) => path.replace(/^\/fallback/, ''),
      // },
 
      // 代理 websockets 或 socket.io 写法：ws://localhost:5173/socket.io -> ws://localhost:5174/socket.io
      // '/socket.io': {
      //   target: 'ws://localhost:5174',
      //   ws: true,
      // },
    // },
  },
})
